﻿Imports System.ComponentModel
Imports System.ComponentModel.Design
Imports System.Drawing

<Designer("System.Windows.Forms.Design.ParentControlDesigner,System.Design", GetType(IDesigner))> _
Public Class InteractivePanel
    Inherits System.Windows.Forms.PictureBox
    Private M_SizeMode As SizeModeEnum = SizeModeEnum.Normal
    Private M_AspectRatio As AspectRatioEnum = AspectRatioEnum.Ratio16x9
    Public Enum SizeModeEnum
        Normal = 0
        AutoWidth = 1
        AutoHeight = 2
    End Enum
    Public Enum AspectRatioEnum
        Ratio16x9 = 1
        Ratio4x3 = 2
        Ratio1x1 = 3
        Ratio235x1 = 4
    End Enum
    Private Sub InitializeComponent()
        Me.SuspendLayout()
        '
        'InteractivePanel
        '
        Me.Name = "InteractivePanel"
        Me.ResumeLayout(False)
        Me.SizeMode = Windows.Forms.PictureBoxSizeMode.Zoom
    End Sub
    Public Overloads Property Size() As Size
        Get
            Return MyBase.Size
        End Get
        Set(ByVal value As Size)
            Dim S As New Size(value.Width, value.Height)
            MyBase.Size = S
        End Set
    End Property
    <System.ComponentModel.Category("Layout")> Public Property AspectRatio() As AspectRatioEnum
        Get
            Return M_AspectRatio
        End Get
        Set(ByVal value As AspectRatioEnum)
            M_AspectRatio = value
        End Set
    End Property
    <System.ComponentModel.Category("Layout")> Public Property AutoSizeMode() As SizeModeEnum
        Get
            Return M_SizeMode
        End Get
        Set(ByVal value As SizeModeEnum)
            M_SizeMode = value
        End Set
    End Property

    Private Sub InteractivePanel_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Resize
        Dim H As Integer
        Dim W As Integer
        If M_SizeMode = SizeModeEnum.Normal Then Exit Sub
        If M_SizeMode = SizeModeEnum.AutoHeight Then
            W = Me.Width
            If M_AspectRatio = AspectRatioEnum.Ratio16x9 Then
                H = Me.Width / (16 / 9)
            End If
            If M_AspectRatio = AspectRatioEnum.Ratio1x1 Then
                H = Me.Width
            End If
            If M_AspectRatio = AspectRatioEnum.Ratio235x1 Then
                H = Me.Width / (2.35 / 1)
            End If
            If M_AspectRatio = AspectRatioEnum.Ratio4x3 Then
                H = Me.Width / (4 / 3)
            End If
            Me.Height = H
            Exit Sub
        End If
        If M_SizeMode = SizeModeEnum.AutoWidth Then
            H = Me.Height
            If M_AspectRatio = AspectRatioEnum.Ratio16x9 Then
                W = Me.Height * (16 / 9)
            End If
            If M_AspectRatio = AspectRatioEnum.Ratio1x1 Then
                W = Me.Height
            End If
            If M_AspectRatio = AspectRatioEnum.Ratio235x1 Then
                W = Me.Height * (2.35 / 1)
            End If
            If M_AspectRatio = AspectRatioEnum.Ratio4x3 Then
                W = Me.Height * (4 / 3)
            End If
            Me.Width = W
            Exit Sub
        End If

    End Sub
End Class
